/**
 * 自用算法库
 */

#ifndef QXGAME_GAMEMATH_H
#define QXGAME_GAMEMATH_H

#include <cmath>
#include <vector>
#include <random>
#include "GameShape.h"
#include "GameVector.h"

#define GAME_EPS 1e-6

namespace GameMath {
    static int Sign(double x, double y)
    {
        if (std::fabs(x - y) < GAME_EPS) return 0;
        if (x < y) return -1;
        return 1;
    }

    static bool CollisionDetection(const GameVector &position, const GameShape &shape,
                                   const GameVector &position2, const GameShape &shape2)
    {
        if (shape.type == ShapeType::RECT && shape2.type == ShapeType::RECT) {
            return !(position.x + shape.w / 2 < position2.x - shape2.w / 2 ||
                     position.x - shape.w / 2 > position2.x + shape2.w / 2 ||
                     position.y + shape.h / 2 < position2.y - shape2.h / 2 ||
                     position.y - shape.h / 2 > position2.y + shape2.h / 2);
        }
        if (shape.type == ShapeType::ROUND && shape2.type == ShapeType::ROUND) {
            return (position - position2).Length() < shape.radius + shape2.radius;
        }
        return false;
    }

    static int RandomInt(int max)
    {
        std::random_device rd;  // 用于获取随机种子
        std::mt19937 gen(rd()); // 以随机设备作为种子的Mersenne Twister生成器
        std::uniform_int_distribution<> dis(1, max); // 定义均匀分布的随机数，范围在1到100之间
        return dis(rd);
    }

}


#endif //QXGAME_GAMEMATH_H
